import { login, verify,loginOut } from "../services/UserService.js";

export default {
    namespaced:true, //打开命名空间，主要是方便mapState使用
    state:{
        data:null,
        isLoading:false
    },
    mutations:{
        setData(state,payload){
            state.data = payload;
        },
        setIsLoading(state,payload){
            state.isLoading = payload;
        }
    },
    actions:{
        async login(context,payload){
            var flag = false;
            context.commit("setIsLoading",true);
            var resp = await login(payload);
            context.commit("setData",resp.data);
            context.commit("setIsLoading",false);
            if(resp.code == 0){
                flag = true;
            }
            return resp.data; 
        },
        async verify(context){
            context.commit("setIsLoading",true);
            var resp = await verify();
            if(resp != null){
                context.commit("setData",resp.data);
            }
            context.commit("setIsLoading",false);

        },
        loginOut(context){
            loginOut();
            context.commit("setData",null);
        }
    }
}